package com.gjy.disruptor.bv1qu411d7oh.t1;

import com.google.common.base.Stopwatch;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.TimeUnit;

/**
 * @author gjy
 * @version 1.0
 * @since 2025-04-04 12:51:47
 */
public class ArrayBlockingTest {

    public static void main(String[] args) {
        // 1.5
        BlockingQueue<Data> query = new ArrayBlockingQueue<>(Constants.EVENT_NUM_OHM);
        Stopwatch stopwatch = Stopwatch.createStarted();

        new Thread(() -> {
            long i = 0;
            while (i < Constants.EVENT_NUM_OHM) {
                Data data = new Data(i, "name: " + i);
                try {
                    query.put(data);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                i++;
            }
        }).start();

        new Thread(() -> {
            long i = 0;
            while (i < Constants.EVENT_NUM_OHM) {
                try {
                    query.take();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                i++;
            }

            long elapsed = stopwatch.elapsed(TimeUnit.MILLISECONDS);
            System.out.println("Array: " + elapsed);
        }).start();

    }
}
